package com.itheima.reggic.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.reggic.common.CustomException;
import com.itheima.reggic.common.R;
import com.itheima.reggic.mapper.CategoryMapper;
import com.itheima.reggic.mapper.EmployeeMapper;
import com.itheima.reggic.pojo.Category;
import com.itheima.reggic.pojo.Dish;
import com.itheima.reggic.pojo.Employee;
import com.itheima.reggic.pojo.Setmeal;
import com.itheima.reggic.service.CategoryService;
import com.itheima.reggic.service.DishService;
import com.itheima.reggic.service.EmployeeService;
import com.itheima.reggic.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PutMapping;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Autowired
    private SetmealService setmealService;

    @Autowired
    private DishService dishService;

    public boolean remove(Long id) {
        Setmeal setmeal = new Setmeal();
        setmeal.setCategoryId(id);
        QueryWrapper<Setmeal> queryWrapper = new QueryWrapper<>(setmeal);

        int count = setmealService.count(queryWrapper);
        if (count > 0)
            throw new CustomException("删除失败,该分类下有套餐！");
        Dish dish = new Dish();
        dish.setCategoryId(id);
        QueryWrapper<Dish> queryWrapper2 = new QueryWrapper<>(dish);

        int count2 = dishService.count(queryWrapper2);
        if (count2 > 0)
            throw new CustomException("删除失败,该分类下有菜品！");

        return removeById(id);
    }


}
